package org.ilead.iserve.service.manager;

import java.util.List;

import org.ilead.iserve.dao.IAreaDAO;
import org.ilead.iserve.model.Area;

public class AreaManager {
	private static AreaManager instance = new AreaManager();
	private List<Area> areaList;
	private IAreaDAO areaDAO;
	
	private AreaManager(){
	}
	
	public static AreaManager getInstance(){
		return instance;
	}
	
	public void setAreaDAO(IAreaDAO areaDAO) {
		this.areaDAO = areaDAO;
	}
	
	public List<Area> getAll(){
		if(areaList == null)
			areaList = areaDAO.findAll();
		return areaList;
	}
	
	public Area getById(int areaId){
		List<Area> list = getAll();
		if(list == null)
			return null;
		
		for (Area area : list){
			if(area.getId().intValue() == areaId){
				return area;
			}
		}
		
		return null;
	}
}
